package binary_search;

public class Demo20250401 {
    public int peakIndexInMountainArray(int[] arr) {
        // 两侧肯定不是峰值，所以left和right起始位置是1和arr.length-2
        int left = 1;
        int right = arr.length - 2;
        while (left < right) {
            int mid = left + (right - left - 1)/2;
            if (arr[mid - 1] < arr[mid]) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }
        return left;
    }
}
